require(['jquery', 'cookie', 'app', "lay"], function ($) {
    require(['vue'], function (Vue) {
        var dic = new Vue({
            el: ".vue-box"
            , data: {
                where: {},
                userInfo: {}
            }
            , created: function () {
                this.userInfo = JSON.parse(localStorage.getItem("userInfo"));
                this.loadPage();
            }
            , methods: {
                loadPage: function () {
                    load();
                    var toolbar = [];
                    var tool = [];

                    toolbar.push({
                        "clas": "layui-btn-danger",
                        "eve": "Y",
                        "tit": "新建",
                        "fnc": function (data) {
                            layui.use(["layer", "admin", 'index'], function () {
                                var b = layui.layer;
                                var $ = layui.jquery, index = layui.index, admin = layui.admin;
                                admin.changeTheme(localStorage.getItem("theme"));
                                // 默认加载主页
                                index.openTab({
                                    title: '新建资讯',
                                    url: '/view/essay/set'
                                })
                            })
                        }
                    });
                    toolbar.push({
                        "clas": "layui-btn-danger",
                        "eve": "U",
                        "tit": "修改",
                        "fnc": function (data) {
                            if (data.length <= 0) {
                                alr("请选择一条记录");
                                return;
                            }
                            layui.use(["layer", "admin", 'index'], function () {
                                var b = layui.layer;
                                var $ = layui.jquery, index = layui.index, admin = layui.admin;
                                // 默认加载主页
                                index.openTab({
                                    title: '更新资讯',
                                    url: '/view/essay/up?id=' + data[0]['id']
                                })
                            })
                        }
                    });
                    toolbar.push({
                        "clas": "layui-btn-danger",
                        "eve": "UD",
                        "tit": "删除",
                        "fnc": function (data) {
                            if (data.length <= 0) {
                                alr("请选择一条记录");
                                return;
                            }
                            var jon = data[0];
                            var re = playDelete("v1/api/essay/" + jon.id, "", "");
                            alr(re.msg);
                            reload();
                        }
                    });
                    bspVIEW($("#authoritiesTable"), "/v1/api/essay/all", [
                        {type: 'radio',width: 150},
                        {type: 'numbers'},
                        {field: 'id', title: 'id', minWidth: 50, width: 120},
                        {field: 'name', title: '资讯名称', minWidth: 50, width: 120},
                        {field: 'label', title: '分类', minWidth: 50, width: 120},
                        {field: 'intro', title: '简介', minWidth: 50, width: 120},
                        {
                            templet: function (d) {
                                if(d.isIndex){
                                    return "是"
                                }else{
                                    return "否"
                                }
                            },
                            align: 'center',
                            width: 120,
                            title: '是否首页'
                            , minWidth: 120
                        },
                        {field: 'createTime', title: '发布时间', minWidth: 50, width: 120},
                        {field: 'modifiedTime', title: '修改时间', minWidth: 50, width: 120},
                    ], {common: this.where}, toolbar, tool, function (res, curr, count) {

                    });
                },
                seachs: function () {
                    this.where = fromName($(".el-form"));
                    this.loadPage();
                },
                refer: function () {

                }
            }
        });
    })
});